<?php
namespace Admin\Controller;

use Think\Controller;


class LoginController extends Controller {


    /**
     * 登陆首页
     */
    public function index(){

        if ($_POST){
            $username = htmlentities($_POST['username']);
            $password = md5($_POST['password']);
            $sdb_webpos_local_store_login = M("webpos_local_store_login");
            $post = ['username' => $username, 'password' => $password];
            $data = $sdb_webpos_local_store_login->where($post)->find();

            $store = M("webpos_local_store")->where(["local_id" => $data['local_id']])->find();

            if (empty($store)) {
                $this->error('登陆失败');
            }

            if ($store['is_self'] == '1') {
                echo '<form style="display:none;" action="'. C("LOCAL_HOST") .'qgs/login/index" method="post" name="form1"><input name="username" type="text" value="'.$username.'"/><input name="password" type="password" value="'.$_POST['password'].'"/><script type="text/javascript">function load_submit(){document.form1.submit()}load_submit();</script>";</form>';
                exit;
            }

            if (!empty($data)) {
                session('userInfo',$data);
            }else {
                $this->error('登陆失败');
            }
            $this->redirect('/admin/index/index');
            exit;
        }
        $this->display();
    }

    /**
     * 退出登陆
     */
    public function loginOut(){
        session(null);
        $this->redirect('/admin/login/index');
    }

}